/**
 * 
 */
package com.novatialabs.qttt.gwt.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;

/**
 * @author nchalko
 * 
 */
public class MoveWidget extends Composite {

  private static final String DEFUALT_TEXT = "";
  private int turn;
  private Label turnDescription;
  private final Notation formater = new GwtHistoryDisplayNotation();

  public MoveWidget(int turn) {
    assert (turn > 0 && turn < 10);
    this.turn = turn;
    FlowPanel panel = new FlowPanel();
    Label turnNumber = new Label(labelText(turn) + ":");
    panel.add(turnNumber);
    turnDescription = new Label();
    initWidget(panel);
  }

  public void setMove(Move move) {
    if (move == null) {
      turnDescription.setText(DEFUALT_TEXT);
    } else {
      turnDescription.setText(formater.printMove(move));
    }

  }

  private String labelText(int turn) {
    return turn + " ( " + (xOrO(turn)) + ")";
  }

  private String xOrO(int turn) {
    return turn % 2 == 0 ? "X" : "O";
  }

}
